package cn.huihuo.weibo.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Dan
 * Created by zhengjunbo on 2015/10/14.
 */
public class TimeUtils {
    public static Long getSpecifiedDayAfter(Long specified,int d,int type) {
        Calendar c = Calendar.getInstance();

        c.setTimeInMillis(specified);
        int day = c.get(type);
        c.set(type, day + d);
        return c.getTime().getTime();
    }

    public static String getTime(Long specified){
        long now = new Date().getTime();

        Long specifiedDayAfter = TimeUtils.getSpecifiedDayAfter(specified, 10, Calendar.SECOND);
        if(now < specifiedDayAfter){
            return  "刚刚";
        }

        Long specifiedDayAfter2 = TimeUtils.getSpecifiedDayAfter(specified, 3, Calendar.MINUTE);
        if(now < specifiedDayAfter2){
            return "一分钟前";
        }

        Long specifiedDayAfter21 = TimeUtils.getSpecifiedDayAfter(specified, 30, Calendar.MINUTE);
        if(now < specifiedDayAfter21){
            return "3分钟前";
        }

        Long specifiedDayAfter22 = TimeUtils.getSpecifiedDayAfter(specified, 1, Calendar.HOUR);
        if(now < specifiedDayAfter22){
            return "半小时前";
        }

        Long specifiedDayAfter3 = TimeUtils.getSpecifiedDayAfter(specified, 3, Calendar.HOUR);
        if(now < specifiedDayAfter3){
            return "一个小时前";
        }

        Long specifiedDayAfter31 = TimeUtils.getSpecifiedDayAfter(specified, 6, Calendar.HOUR);
        if(now < specifiedDayAfter31){
            return "三个小时前";
        }

        Long specifiedDayAfter32 = TimeUtils.getSpecifiedDayAfter(specified, 12, Calendar.HOUR);
        if(now < specifiedDayAfter32){
            return "六个小时前";
        }

        Long specifiedDayAfter33 = TimeUtils.getSpecifiedDayAfter(specified, 16, Calendar.HOUR);
        if(now < specifiedDayAfter33){
            return "十二个小时前";
        }

        Long specifiedDayAfter5 = TimeUtils.getSpecifiedDayAfter(specified, 3, Calendar.DATE);
        if(now < specifiedDayAfter5){
            return "一天前";
        }

        Long specifiedDayAfter6 = TimeUtils.getSpecifiedDayAfter(specified, 1, Calendar.WEEK_OF_MONTH);
        if(now < specifiedDayAfter6){
            return "三天前";
        }

        Long specifiedDayAfter7 = TimeUtils.getSpecifiedDayAfter(specified, 2, Calendar.WEEK_OF_MONTH);
        if(now < specifiedDayAfter7){
            return "一周前";
        }

        Long specifiedDayAfter8 = TimeUtils.getSpecifiedDayAfter(specified, 1, Calendar.MONTH);
        if(now < specifiedDayAfter8){
            return "两周前";
        }

        Long specifiedDayAfter9 = TimeUtils.getSpecifiedDayAfter(specified, 3, Calendar.MONTH);
        if(now < specifiedDayAfter9){
            return "一月前";
        }

        Long specifiedDayAfter10 = TimeUtils.getSpecifiedDayAfter(specified, 6, Calendar.MONTH);
        if(now < specifiedDayAfter10){
            return "三月前";
        }

        Long specifiedDayAfter11 = TimeUtils.getSpecifiedDayAfter(specified, 1, Calendar.YEAR);
        if(now < specifiedDayAfter11){
            return "半年前";
        }

        Long specifiedDayAfter12 = TimeUtils.getSpecifiedDayAfter(specified,2, Calendar.YEAR);
        if(now < specifiedDayAfter12){
           return  "一年前";
        }

        return new SimpleDateFormat("yyyy-MM-dd").format(new Date(specified));

    }
}
